#include "dbdialog.h"

DbDialog::DbDialog()
{
setupUi(this);

app_dir = QCoreApplication::applicationDirPath();

QObject::connect(dbFileToolButton,
                 SIGNAL(clicked()),
                 this,
                 SLOT(setDatabaseName()));

}

void DbDialog::setDatabaseName()
{
QString filename = QFileDialog::getOpenFileName(this,
                   tr("Select Database"),
                   app_dir,
                   tr("Firebird DB (*.fdb *.ib);;All Files (*)"));
    if ( !filename.isEmpty() )
    {
    QString native_filename = QDir::toNativeSeparators(filename);
    dbNameLineEdit->setText(native_filename);
    }
}

QMap<QString, QVariant> DbDialog::return_config()
{
QMap<QString, QVariant> m;

    if ( true == embCheckBox->isChecked() )
    {
    m["is_emb_db"] = QVariant( QLatin1String("y") );
    }
    else
    {
    m["is_emb_db"] = QVariant( QLatin1String("n") );
    m["db"]   = QVariant( dbNameLineEdit->text() );

        if (true == dbCredCheckBox->isChecked() )
        {
        m["user"] = QVariant( dbUsrLineEdit->text() );
        m["pass"] = QVariant( dbPasswdLineEdit->text() );
        }
        else
        {
        m["user"] = QVariant( QLatin1String("") );
        m["pass"] = QVariant( QLatin1String("") );
        }

        if ( true == dbHostCheckBox->isChecked() )
        {
        m["host"] = QVariant( dbHostComboBox->currentText() );
        m["port"] = QVariant( dbPortSpinBox->value() );
        }
    }
return m;
}
